from django.db import models
from users.models import Users
import django.utils.timezone

# Create your models here.

'''
本模型中涉及到的物理学计量单位说明如下：
功率：kW
气体：m^3/h
压强：kPa.G
容量：L
'''


class ICE(models.Model):
    """
    内燃机 Internal combustion engine
    """
    model_name = models.CharField(max_length=50, unique=True)  # 型号名称
    max_power = models.FloatField()  # 最大功率
    heat_production = models.FloatField()  # 产热量
    power_generation = models.FloatField()  # 发电量
    heat_effect = models.FloatField()  # 热效率
    power_effect = models.FloatField()  # 电效率
    ppp = models.FloatField(default=0)  # price per power 单位功率费用（元/kWh）
    is_default = models.BooleanField(default=False)


class GasBoiler(models.Model):
    """
    燃气锅炉
    """
    model_name = models.CharField(max_length=50, unique=True)  # 型号名称
    max_in_power = models.FloatField()  # 最大输入功率
    out_power = models.FloatField()  # 输出功率
    heat_effect = models.FloatField()  # 热效率
    ppp = models.FloatField(default=0)  # price per power 单位功率费用（元/kWh）
    is_default = models.BooleanField(default=False)


class ElectricBoiler(models.Model):
    """
    电锅炉
    """
    model_name = models.CharField(max_length=50, unique=True)  # 型号名称
    max_in_power = models.FloatField()  # 最大输入功率
    max_out_power = models.FloatField()  # 最大输出功率
    heat_effect = models.FloatField()  # 热效率
    ppp = models.FloatField(default=0)  # price per power 单位功率费用（元/kWh）
    is_default = models.BooleanField(default=False)


class AR(models.Model):
    """
    吸收式制冷机 Absorption refrigerator 单独使用时使用
    """
    model_name = models.CharField(max_length=50, unique=True)  # 型号名称
    cool_cap = models.FloatField()  # 制冷量
    heat_cap = models.FloatField()  # 供热量
    income_pressure = models.FloatField()  # 进口压力
    pay_to_cool = models.FloatField()  # 耗量（制冷）
    pay_to_heat = models.FloatField()  # 耗量（制热）
    income_cool = models.FloatField()  # 制冷输入功率
    income_heat = models.FloatField()  # 制热输入功率
    heat_effect = models.FloatField()  # 制热效率
    cool_effect = models.FloatField()  # 制冷效率
    ppp = models.FloatField(default=0)  # price per power 单位功率费用（元/kWh）
    is_default = models.BooleanField(default=False)


class ARS(models.Model):
    """
    吸收式制冷机 Absorption refrigerator 三联供系统中使用的
    烟气热水机
    """
    model_name = models.CharField(max_length=50, unique=True)  # 型号名称
    cool_cap = models.FloatField()  # 制冷量
    effect = models.FloatField(default=0.76)  # 制冷效率
    input_power = models.FloatField()  # 输入功率
    is_default = models.BooleanField(default=False)


class IceTank(models.Model):
    """
    蓄冰槽
    """
    model_name = models.CharField(max_length=50, unique=True)  # 型号名称
    heat_capacity = models.FloatField()  # 蓄冰潜热容量kW
    storage = models.FloatField()  # 蓄冰槽容量
    effect = models.FloatField()  # 充放能效率
    max_prop = models.FloatField()  # 储能占比上限
    min_prop = models.FloatField()  # 储能占比上限
    ppp = models.FloatField(default=0)  # price per power 单位功率费用（元/kWh）
    is_default = models.BooleanField(default=False)


class ERU(models.Model):
    """
    电制冷机组 Electric refrigeration unit
    """
    model_name = models.CharField(max_length=50, unique=True)  # 型号名称
    ice_effect = models.FloatField()  # 制冰效率
    cool_effect = models.FloatField()  # 制冷效率
    power_to_ice = models.FloatField()  # 制冰功率
    power_to_cool = models.FloatField()  # 制冷功率
    input_ice_power = models.FloatField()  # 制冰输入功率
    input_cool_power = models.FloatField()  # 制冷输入功率
    ppp = models.FloatField(default=0)  # price per power 单位功率费用（元/kWh）
    is_default = models.BooleanField(default=False)


class AirPump(models.Model):
    """
    风冷热泵 Air cooled heat pump
    """
    model_name = models.CharField(max_length=50, unique=True)  # 型号名称
    make_cool_power = models.FloatField()  # 制冷量
    input_power = models.FloatField()  # 制冷输入功率
    effect = models.FloatField()  # 效率
    ppp = models.FloatField(default=0)  # price per power 单位功率费用（元/kWh）
    is_default = models.BooleanField(default=False)


class GroundPump(models.Model):
    """
    地源热泵 Ground source heat pump
    """
    model_name = models.CharField(max_length=50, unique=True)  # 型号名称
    output_cool_power = models.FloatField()  # 输出冷量
    input_cool_power = models.FloatField()  # 制冷输入功率
    make_cool_effect = models.FloatField()  # 制冷效率
    output_heat_power = models.FloatField()  # 输出热量
    input_heat_power = models.FloatField()  # 制热输入功率
    make_heat_effect = models.FloatField()  # 制热效率
    ppp = models.FloatField(default=0)  # price per power 单位功率费用（元/kWh）
    is_default = models.BooleanField(default=False)


class GasTurbine(models.Model):
    """
    燃气轮机
    """
    model_name = models.CharField(max_length=50, unique=True)  # 型号名称
    input_power = models.FloatField()  # 输入功率
    generation_power = models.FloatField()  # 发电功率
    generation_effect = models.FloatField()  # 发电效率
    waste_heat = models.FloatField()  # 余热
    heat_effect = models.FloatField()  # 热效率
    ppp = models.FloatField(default=0)  # price per power 单位功率费用（元/kWh）
    is_default = models.BooleanField(default=False)


class WindPower(models.Model):
    """
    风力发电
    """
    model_name = models.CharField(max_length=50, unique=True)  # 型号名称
    s2 = models.FloatField(default=0)  # 风速2.5处理
    s3 = models.FloatField(default=0)  # 风速N出力，默认为0，为不出力
    s4 = models.FloatField(default=0)
    s5 = models.FloatField(default=0)
    s6 = models.FloatField(default=0)
    s7 = models.FloatField(default=0)
    s8 = models.FloatField(default=0)
    s9 = models.FloatField(default=0)
    s10 = models.FloatField(default=0)
    s11 = models.FloatField(default=0)
    s12 = models.FloatField(default=0)
    s13 = models.FloatField(default=0)
    s14 = models.FloatField(default=0)
    s15 = models.FloatField(default=0)
    s16 = models.FloatField(default=0)
    s17 = models.FloatField(default=0)
    s18 = models.FloatField(default=0)
    s19 = models.FloatField(default=0)
    s20 = models.FloatField(default=0)
    s21 = models.FloatField(default=0)
    s22 = models.FloatField(default=0)
    s23 = models.FloatField(default=0)
    s24 = models.FloatField(default=0)
    s25 = models.FloatField(default=0)
    ppp = models.FloatField(default=0)  # price per power 单位功率费用（元/kWh）
    is_default = models.BooleanField(default=False)


class PVP(models.Model):
    """
    太阳能光伏板 Photovoltaic panel
    """
    model_name = models.CharField(max_length=50, unique=True)  # 型号名称
    max_power = models.FloatField()  # 最大功率
    ppp = models.FloatField(default=0)  # price per power 单位功率费用（元/kWh）
    is_default = models.BooleanField(default=False)


class Buttery(models.Model):
    """
    蓄电池 Buttery
    """
    model_name = models.CharField(max_length=50, unique=True)  # 型号名称
    capacity = models.FloatField()  # 配置容量
    rv = models.FloatField(default=0)  # 额定电压
    uv = models.FloatField(default=0)  # 上行电压
    dv = models.FloatField(default=0)  # 下行电压
    u_cdp = models.FloatField(default=0)  # 充放功率上限
    l_cdp = models.FloatField(default=0)  # 充放功率下限
    u_scr = models.FloatField(default=0)  # 储能占比上限
    l_scr = models.FloatField(default=0)  # 储能占比下限
    effect = models.FloatField(default=0)  # 充放效率
    ppu = models.FloatField(default=0)  # 单位容量价格（元/kWh）
    sp = models.FloatField(default=0)  # 系统投资（元/kW）
    is_default = models.BooleanField(default=False)


class CalResult(models.Model):
    # which = models.CharField(max_length=100)  # 归属
    design_id = models.CharField(max_length=30, default='')  # 设计id
    target_date = models.CharField(max_length=6)  # 日期
    target_time = models.FloatField(default=0)  # 时间点
    ice_os = models.FloatField(default=0)  # CCHP发电
    ice_ig = models.FloatField(default=0)  # 内燃机输入
    gp_ieh = models.FloatField(default=0)  # 地源热泵耗电
    gp_oh = models.FloatField(default=0)  # 地源热泵供热
    gp_oc = models.FloatField(default=0)  # 地源热泵供冷
    ap_ie = models.FloatField(default=0)  # 风冷热泵耗电
    ap_oc = models.FloatField(default=0)  # 风冷热泵供冷
    gb_ig = models.FloatField(default=0)  # 燃气锅炉耗气
    gb_oh = models.FloatField(default=0)  # 燃气锅炉供热
    ar_ig = models.FloatField(default=0)  # 吸收式制冷机耗气
    ar_oc = models.FloatField(default=0)  # 吸收式制冷机供冷
    eb_ie = models.FloatField(default=0)  # 电锅炉耗电
    eb_oh = models.FloatField(default=0)  # 电锅炉供热
    it_ch = models.FloatField(default=0)  # 冷水机组耗电
    it_dis = models.FloatField(default=0)  # 冰蓄冷
    ele_buy = models.FloatField(default=0)  # 购电量
    ele_pri = models.FloatField(default=0)  # 购电费用
    gas_buy = models.FloatField(default=0)  # 购气量
    gas_pri = models.FloatField(default=0)  # 购气费用
    heat_buy = models.FloatField(default=0)  # 购热量
    heat_pri = models.FloatField(default=0)  # 购热费用
    ele_sell = models.FloatField(default=0)  # 售电量
    ele_inc = models.FloatField(default=0)  # 收入
    wind = models.FloatField(default=0)  # 风机
    PV = models.FloatField(default=0)  # 光伏板
    cchp_oh = models.FloatField(default=0)  # CCHP供热
    cchp_oc = models.FloatField(default=0)  # CCHP供冷
    is_correct = models.BooleanField(default=True)  # 是否规划成功
    heat_load = models.FloatField(default=0)  # 热负载
    cold_load = models.FloatField(default=0)  # 冷负载
    ele_load = models.FloatField(default=0)  # 电负载
    sell_h = models.FloatField(default=0)  # 售热收益
    sell_c = models.FloatField(default=0)  # 售冷收益
    sell_e = models.FloatField(default=0)  # 售电收益
    wind_power = models.FloatField(default=0)  # 风机出力
    pvp_power = models.FloatField(default=0)  # 光伏出力
    co2_em = models.FloatField(default=0)  # 二氧化碳排放
    nox_em = models.FloatField(default=0)  # 氮氧化物排放
    ele_ch = models.FloatField(default=0)  # 充电功率
    ele_dis = models.FloatField(default=0)  # 放电功率


class DesignPlan(models.Model):
    """
    用户方案表
    """
    design_id = models.CharField(max_length=50, default='', unique=True)  # 方案id
    d_name = models.CharField(max_length=50, default='项目名称')  # 方案名称
    d_desc = models.CharField(max_length=100, blank=True, default='')  # 方案描述
    time = models.DateTimeField(default=django.utils.timezone.now)  # 保存日期
    belongs = models.ForeignKey(Users, on_delete=models.DO_NOTHING, default=0)  # 归属人
    model_which = models.IntegerField(default=0)  # 系统配置模式 0:孤岛模式,1:并网不上网,2:并网上网
    opt_target = models.IntegerField(default=0)  # 优化目标：0：经济性；1：能耗性
    summer_day = models.CharField(blank=True, default='', max_length=5)  # 典型夏季日
    winter_day = models.CharField(blank=True, default='', max_length=5)  # 典型冬季日
    model_buy_gas = models.BooleanField(default=False)  # 是否买气
    model_buy_heat = models.BooleanField(default=False)  # 是否买热
    cchp_is_selected = models.BooleanField(default=False)  # cchp是否选中
    cchp_max_power = models.FloatField(default=0)  # cchp最大出力
    ars_is_selected = models.BooleanField(default=False)  # 是否选中烟气热水机
    ars_which = models.CharField(blank=True, default="", max_length=25)  # 烟气热水机型号
    ice_is_selected = models.BooleanField(default=False)  # 内燃机是否选中
    ice_which = models.CharField(blank=True, default="", max_length=25)  # 内燃机型号
    gt_is_selected = models.BooleanField(default=False)  # 燃气轮机是否选中
    gt_which = models.CharField(blank=True, default='', max_length=25)  # 燃气轮机型号
    ar_is_selected = models.BooleanField(default=False)  # 吸收式制冷机是否选中
    ar_which = models.CharField(blank=True, default="", max_length=25)  # 吸收式制冷机型号
    re_is_selected = models.BooleanField(default=False)  # 可再生能源是否选中
    wind_is_selected = models.BooleanField(default=False)  # 风机是否选中
    wind_which = models.CharField(blank=True, default='', max_length=25)  # 风机型号
    solar_is_selected = models.BooleanField(default=False)  # 光伏是否选中
    solar_which = models.CharField(blank=True, default='', max_length=25)  # 光伏型号
    hp_is_selected = models.BooleanField(default=False)  # 热泵是否选中
    gp_is_selected = models.BooleanField(default=False)  # 地源热泵是否选中
    gp_which = models.CharField(blank=True, default='', max_length=25)  # 地源热泵型号
    gp_max_power = models.FloatField(default=0)  # 地源热泵最大出力
    ap_is_selected = models.BooleanField(default=False)  # 风冷热泵是否选中
    ap_which = models.CharField(blank=True, default='', max_length=25)  # 风冷热泵型号
    ap_max_power = models.FloatField(default=0)  # 风冷热泵最大出力
    boiler_is_selected = models.BooleanField(default=False)  # 锅炉是否选中
    gb_is_selected = models.BooleanField(default=False)  # 燃气锅炉是否选中
    gb_which = models.CharField(blank=True, default='', max_length=25)  # 燃气锅炉型号
    gb_max_power = models.FloatField(default=0)  # 燃气锅炉最大出力
    eb_is_selected = models.BooleanField(default=False)  # 电锅炉是否选中
    eb_which = models.CharField(blank=True, default='', max_length=25)  # 电锅炉型号
    eb_max_power = models.FloatField(default=0)  # 电锅炉最大出力
    ese_is_selected = models.BooleanField(default=False)  # 储能装置是否选中
    ice_storage_is_selected = models.BooleanField(default=False)  # 冰蓄冷装置是否选中
    ice_storage_max_capacity = models.FloatField(default=0)  # 冰蓄冷最大容量
    ice_storage_max_power = models.FloatField(default=0)  # 冰蓄冷最大功率
    cu_is_selected = models.BooleanField(default=False)  # 蓄冷机组是否选中
    cu_which = models.CharField(blank=True, default='', max_length=25)  # 冷水机组型号
    it_is_selected = models.BooleanField(default=False)  # 蓄冰槽是否选中
    it_which = models.CharField(blank=True, default='', max_length=25)  # 蓄冰槽型号
    heat_storage_is_selected = models.BooleanField(default=False)  # 储热装置是否选中
    heat_storage_max_capacity = models.FloatField(default=0)  # 储热最大容量
    heat_storage_max_powerch = models.FloatField(default=0)  # 充能功率
    heat_storage_max_powerdis = models.FloatField(default=0)  # 放能功率
    heat_storage_efficiency = models.FloatField(default=0)  # 储热效率
    ele_storage_is_selected = models.BooleanField(default=False)  # 储电设备是否选中
    ele_storage_max_capacity = models.FloatField(default=0)  # 储电设备最大容量
    battery_is_selected = models.BooleanField(default=False)  # 是否选中电池
    battery_which = models.CharField(blank=True, default='', max_length=25)  # 电池型号
    # =====================
